<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 17-6-21
 * Time: 下午5:12
 */

namespace wodrow\tools;


class Db
{
//    public static function getRaws($sql)
//    {
//        $res = \ORM::raw_execute($sql);
//        $statement = \ORM::get_last_statement();
//        $rows = array();
//        while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
//            $rows[] = $row;
//        }
//        return $rows;
//    }

    public static function getConditions($where)
    {
        $conditions = array();
//        $where = [
//            ['=', 'author_id', 1],
//            ['in', 'author_id', array()],
//        ];
        foreach ($where as $k => $v) {
            switch ($v[0]){
                case '='||'>'||'<':
                    $conditions['conditions'][] = "`{$v[1]}` {$v[0]} ?";
                    $conditions[] = $v[2];
                    break;
                case 'in':
                    $conditions['conditions'][] = "`{$v[1]}` in(?)";
                    $conditions[] = $v[2];
                    break;
            }
        }
        $conditions['conditions'] = ArrayHelp::arr2str($conditions['conditions'], ' AND ');
//        $conditions = array('conditions'=>array('author_id in(?) AND price < ?', array(1,2,3), 15.00));
        $conditions = array_values($conditions);
        return $conditions;
    }
}